package com.jh.paymentchannel.repository.freeQuick;

import com.jh.paymentchannel.pojo.freeQuick.FreeQuickOrder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FreeQuickOrderRepository extends JpaRepository<FreeQuickOrder, String>,
        JpaSpecificationExecutor<FreeQuickOrder> {

    @Query("select f from FreeQuickOrder f where f.requestNo = :requestNo and f.merchantNo = :merchantNo")
    FreeQuickOrder findFreeQuickOrderByMerchantNoAndRAndRequestNo(@Param("requestNo")String requestNo,@Param("merchantNo")String merchantNo);

    @Query("select f from FreeQuickOrder f where f.payStatus = '0'")
    List<FreeQuickOrder> getAllInProcess();

    @Query("select f from FreeQuickOrder f where f.payStatus = 0")
    List<FreeQuickOrder> getAllInProcessPayStatus();

    @Modifying
    @Query("update FreeQuickOrder f set f.payStatus = :resultStatus where f.requestNo = :requestNo")
    int updateByRequestNo(@Param("resultStatus") String resultStatus, @Param("requestNo") String requestNo);

    FreeQuickOrder findByRequestNo(String requestNo);
}
